import 'package:flutter/material.dart';
import 'cart_num.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../widget/my_image.dart';
import 'package:provider/provider.dart';
import '../../provider/cart.dart';

class CartItem extends StatefulWidget {
  CartItem({this.itemData});

  final Map<String, dynamic> itemData;

  _CartItemState createState() => _CartItemState();
}

class _CartItemState extends State<CartItem> {

  bool isSelect=true;
  @override
  Widget build(BuildContext context) {
    var cart = Provider.of<Cart>(context);
    return Container(
      height: 220.h,
      padding: EdgeInsets.all(5),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(bottom: BorderSide(width: 1, color: Colors.black12))),
      child: Row(
        children: <Widget>[
          Container(
            width: 60.w,
            child: Checkbox(
              value: isSelect,
              onChanged: (val) {
                print(val);
                List a=[];
                print(widget.itemData['mallStoreProduct']['cateid']);
                setState(() => isSelect = val);
                if(cart.selectCart.contains(widget.itemData['mallStoreProduct']['cateid'])){
                  cart.removeSelectCart(widget.itemData['mallStoreProduct']['cateid']);

                }else{
                  cart.addSelectCart(widget.itemData['mallStoreProduct']['cateid']);
                }
//                cart.addSelectCart(val);
//                if(val==false){
//                  cart.addSelectCart(val);
//                }
//                _itemData["checked"] = !_itemData["checked"];
              },
              activeColor: Colors.pink,
            ),
          ),
          Container(
            width: 160.w,
            child: MyImage(
                imgSrc: "${widget.itemData['mallStoreProduct']["image"]}"),
          ),
          Expanded(
            flex: 1,
            child: Container(
              padding: EdgeInsets.fromLTRB(10, 10, 10, 5),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text("${widget.itemData['mallStoreProduct']["productName"]}",
                      maxLines: 2),
                  Text("${widget.itemData['mallStoreProductAttrValue']["suk"]}",
                      maxLines: 2),
                  Stack(
                    children: <Widget>[
                      Align(
                        alignment: Alignment.centerLeft,
                        child: Text(
                            "￥${widget.itemData['mallStoreProduct']["price"]}",
                            style: TextStyle(color: Colors.red)),
                      ),
                      Align(
                        alignment: Alignment.centerRight,
                        child: CartNum(widget.itemData),
                      )
                    ],
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
